package cn.zhaoyuening.hnistalumnirecord.utils;

import org.apache.commons.io.FileUtils;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

/**
 * Created by Zhao on 2017/2/23.
 */
public class ImgUploadUtils {
    //文件保存的文件夹

    /**
     * 处理文件上传
     * @param file 需要上传的文件
     * @param rootPath webapp更目录地址 session.getServletContext().getRealPath("/");
     * @param fileName 文件保存名
     * @param fileSaveFolder 文件保存目录
     * @return 文件位于rootPath下的保存的相对路径
     * @throws IOException
     */
    public static String uploadImage(MultipartFile file, String rootPath,String fileSaveFolder,String fileName) throws IOException {
        //处理图上传
        if ((!(file ==null))&&(!file.isEmpty())){
            File savePath = new File(rootPath+ fileSaveFolder+fileName);
            FileUtils.copyInputStreamToFile(file.getInputStream(),savePath);
        }
        return fileSaveFolder+fileName;
    }
}
